home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / GENetReleaseƒ / GEDemo / Walk.c < prev    next >
Text File  |  1994-03-07  |  3KB  |  94 lines

  1. /*
  2.     Walk.c
  3.     
  4.     Animated walking figure on balcony
  5.     
  6.     Copyright 1993 by Al Evans. All rights reserved.
  7.     
  8.     11/8/93
  9.     
  10. */
  11.  
  12. #include "Walk.h"
  13. #include "Motion.h"
  14.  
  15. Boolean LoadBalconyScene(GEWorldPtr world)
  16. {
  17.     GrafElPtr        thisElement;
  18.     Rect            balconyBox;            //Walking figure is positioned relative to balcony
  19.     short            elemHeight;
  20.     MParamPtr        walkMotion;
  21.     
  22.     //Get railing of balcony
  23.     thisElement = NewBasicPICT(world, balconyID, balconyPlane, rBalconyPic,
  24.                                 transparent, balconyLeft, balconyTop);
  25.     if (thisElement == nil) return false;
  26.     balconyBox = thisElement->animationRect;
  27.     
  28.     //Get walking figure
  29.     thisElement = NewAnimatedGraphic(world, walkID, walkPlane, rAnimWalk,
  30.                                 transparent, 0, 0, 10);
  31.     if (thisElement == nil) return false;
  32.  
  33.     //Position figure relative to balcony
  34.     elemHeight = thisElement->graphRect.bottom - thisElement->graphRect.top;
  35.     MoveElementTo(world, walkID, balconyBox.left + 20, balconyBox.bottom - 10 - elemHeight);
  36.     
  37.     //Initialize motion fields -- never collide with top or bottom
  38.     walkMotion = (MParamPtr) NewPtrClear(sizeof(MotionParams));
  39.     InitMotion(walkMotion, 100, 100);
  40.     walkMotion->currMotion.h = 6;
  41.     walkMotion->limitRect.top  = 0;
  42.     walkMotion->limitRect.left = balconyBox.left + 5;
  43.     walkMotion->limitRect.bottom = 1000;
  44.     walkMotion->limitRect.right = balconyBox.right - 16;
  45.     
  46.     //Initialize figure's walking action
  47.     SetAutoChange(world, walkID, DoWalker, (Ptr) walkMotion, 133);
  48.     
  49.     //And set animation style to "loop"
  50.     ((SeqGraphicPtr) thisElement)->seq = loop;
  51.     
  52.     //Load speed control slider
  53.     thisElement = NewSliderSensor(world, sliderID, sliderPlane, rSliderBkg, 
  54.                     sliderLeft, sliderTop, hSlideSensor, rSliderCtrl);
  55.     if (thisElement == nil) return false;
  56.     SetSliderPercent(world, sliderID, 50);
  57.     SetSensorAction(world, sliderID, AdjustSpeed);
  58.     
  59.     return true;
  60. }
  61.  
  62.  
  63. pascal void DoWalker(GEWorldPtr world, GrafElPtr walker)
  64. {
  65.     MParamPtr    motion;
  66.     GEDirection    collisionDir;
  67.     
  68.     motion = (MParamPtr) walker->changeData;
  69.     collisionDir = CheckLimits(&walker->animationRect, &motion->limitRect);
  70.     if ((collisionDir == left) || (collisionDir == right)) {
  71.         motion->currMotion.h = -motion->currMotion.h;
  72.         SetMirroring(world, walker->objectID, (collisionDir == right), false);
  73.     }
  74.     MoveElement(world, walker->objectID, motion->currMotion.h, motion->currMotion.v);
  75.     BumpFrame(world, walker->objectID);
  76. }
  77.  
  78. pascal void AdjustSpeed(GEWorldPtr world, short newSpeed)
  79. {
  80.     GrafElPtr walker;
  81.     long newIntrvl;
  82.     
  83.     walker = FindElementByID(world, walkID);
  84.     if (walker) {
  85.         newIntrvl = (newSpeed * 240) / 100;
  86.         if (newIntrvl > 0) {
  87.             newIntrvl = 240 - newIntrvl;
  88.             if (newIntrvl < 16)
  89.                 newIntrvl = 16;
  90.         }
  91.         walker->changeIntrvl = newIntrvl;
  92.     }
  93. }
  94.